<?php

/**
 * 后台首页
 */
class MemberAction extends AdminbaseAction {
	
	
	function _initialize() {
		parent::_initialize();

	}

    public function index() {

    	$users = M('member')->select();
        $this->users = $users;

    	$this->display();

    }

    /**
     * 修改用户资料
     * @return [type] [description]
     */
    public function edit(){
        $map['id'] = I('get.id');
        $info = M('member')->where($map)->find();
        $this->info = $info;
        $this->display();
    }


    public function handleEdit(){
        // p($_POST);
        if($_POST['new_pwd']){
            if($_POST['new_pwd'] != $_POST['repeat_pwd']){
                $this->error('密码不一致，更新失败');
            }else{
                $data['password'] = md5($_POST['new_pwd']);
            }
        }
        $map['id'] = $_POST['uid'];
        $data['name'] = I('post.name');
        $data['email'] = I('post.email');
        $data['status'] = I('post.status');
        if(I('post.phone'))
            $data['phone'] = I('post.phone');

        $res = M('member')->where($map)->save($data);
        if($res){
            $this->success('更新成功');
        }else{
            $this->error('资料未更改，更新失败');
        }
    }
    

}

